﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Web.Mvc;

namespace PP.Controllers
{
    public class DonateController : Controller
    {
        //
        // GET: /Donate/

		public ActionResult Form()
		{
			return PartialView();
		}

		[HttpGet]
        public ActionResult Index()
        {
            return View();
        }

		[HttpPost]
		public ActionResult Index(FormCollection form)
		{
			//Send Email
            using (SmtpClient client = new SmtpClient())
            {
                var mail = new MailMessage();
                mail.From = new MailAddress("donationsubmission@pinkpetals.org");
                mail.To.Add(new MailAddress("pink.petals@pinkpetals.org"));
                mail.Subject = "New Donation in Someone's Name";
                mail.IsBodyHtml = true;

                foreach (string key in form.Keys)
                {
                    if (form[key] != null && !string.IsNullOrWhiteSpace(form[key].ToString()))
                        mail.Body += key + ": " + form[key].ToString().Trim() + "<br/>";
                }

                client.Send(mail);
            }

			if (Request.IsAjaxRequest())
			{
				return Content("1");
			}
			else
			{
				ViewData["Message"] = "The donation request has been sent.  Please use the button below to make the donation.  Thank you.";
				return View();
			}
		}

    }
}
